/**
 * 功能描述 表格
 */

define(function (require, exports, module) {
	var Grid = require("grid");
	var aw = require("ajaxwrapper");
	var Dialog = require("dialog");
	var store =require("store");
    var instance = {
    	initComponent: function (widget){
    		var grid = new Grid({
    			parentNode:".J-grid",
				model:{
					url:"api/producttype/query",
					params:function(){
						return {
							seal: widget.get("subnav").getValue("seal"),
							fetchProperties:widget.constant.fetchProperties
						};
					},
					columns:[{
						className:"col-md-3",
						name:"product.name",
						label:"产品名称"
					},{
						className:"col-md-3",
						name:"name",
						label:"产品类型"
					},{
						className:"col-md-3",
						name:"seal",
						label:"状态",
						format:function(seal){
							if(seal == true){
								return "停用";
							}else{
								return "启用";
							}
						}
					},{
						className:"col-md-3",
						name:"show",
						label:"操作",
						format:"button",
						formatparams:[{
							id:"enable",
							text:"启用",
							show:function(value,row){
								return row.seal;
							},
							handler:function(index,data,rowEle){
								widget.service.changeSeal({
									pkProductType: data.pkProductType,
                                    seal: false
								},function(){
									widget.get("grid").refresh();
								})
							}
						},{
							id:"disable",
							text:"停用",
							show:function(value,row){
								return !row.seal;
							},
							handler:function(index,data,rowEle){
								widget.service.changeSeal({
									pkProductType: data.pkProductType,
									seal: true
								},function(){
									widget.get("grid").refresh();
								})
							}
						},{
							id:"edit",
							icon:"icon-edit",
							handler:function(index,data,rowEle){
								widget.service.seekQuote({
									"pkProductType":data.pkProductType
								},function(flag){
									if(flag == true){
										Dialog.alert({content:"数据已被引用,不可修改"});
										return false;
									}else{
										widget.toCard();
										var form = widget.get("form");
										form.reset();
										form.setData(data);
									}
								});
							}
						},{
							id:"delete",
							icon:"icon-remove",
							handler:function(index,data,rowEle){
								widget.service.seekQuote({
									"pkProductType":data.pkProductType
								},function(flag){
									if(flag == true){
										Dialog.alert({content:"数据已被引用,不可删除"});
										return false;
									}else{
										widget.service.del(data.pkProductType,function(){
											grid.refresh();
										});
									}
								});
							}
						}]
					}]
				}
    		});
    		widget.set("grid", grid);
        }
    };
    module.exports = instance;
});
